package com.educate.educms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.educate.commonutils.ResultOne;
import com.educate.educms.entity.CrmBanner;
import com.educate.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台banner管理接口
 * </p>
 *
 * @author educate.wht
 * @since 2022-08-23
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService crmBannerService;
    //1分页查询banner
    @GetMapping("pageBanner/{page}/{limit}")
    public ResultOne pageBanner(@PathVariable Long page,@PathVariable Long limit){
        Page<CrmBanner> pageBanner=new Page<>(page,limit);
        crmBannerService.page(pageBanner, null);
        return ResultOne.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getRecords());
    }
    //2添加banner
    @PostMapping("addBanner")
    public ResultOne addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return ResultOne.ok();
    }
    //3根据id查询banner
    @GetMapping("getBanner/{id}")
    public ResultOne get(@PathVariable String id){
        CrmBanner banner = crmBannerService.getById(id);
        return ResultOne.ok().data("item",banner);

    }

    //4修改banner
    @PutMapping("updateBanner")
    public ResultOne updateById(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return ResultOne.ok();
    }
    //5删除banner
    @DeleteMapping("deleteBanner/{id}")
    public ResultOne remove(@PathVariable String id){
        crmBannerService.removeById(id);
        return ResultOne.ok();
    }


}

